import { Component, OnInit } from '@angular/core';
import { ApiService } from 'src/app/core/api';
import { MessageService } from 'src/app/core/service/message.service';
import { FormBuilder, Validators } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { I18nService } from 'src/app/core/i18n/i18n.service';

@Component({
    templateUrl: './index.html',
    styles: [
        `
          .tab-head .ant-btn{
            margin-right: 12px;
          }
          .tab-head .ant-input-search-button{
              margin:0;
          }
          .xq-item{
            margin-bottom: 20px;
            font-size:13px;
          }
          .xq-item span{
            color:#999;
          }
          
        `
    ],

})
export class RechargeComponent implements OnInit {
    page = {
        pageNo: 1,
        sn: "",
        loginId: "",
        beginTime: '',
        endTime: '',
	};
	pages;
    dateRange;
    dataList = [];
    isVisible = false;
    isOkLoading = false;
    tableLoading = false;
    modalTitle;
    selectedRowData: any = { logList:[]};
	validateForm;
    prepareMemo = '';
    rechargeStatus = {};
    constructor(
        private apiService: ApiService,
        private message: MessageService,
        private fb: FormBuilder,
        private date: DatePipe,
		private nzMessageService: NzMessageService,
        private modalService: NzModalService,
        private i18n:I18nService
    ) {
        this.i18n.get(['rechargeStatus','pagetitle']).subscribe(res=>{
            this.rechargeStatus = res.rechargeStatus;
            const pagetitle = res.pagetitle;
            this.message.setBreadcrumb({
                breadcrumbs: [{ name: pagetitle.title7}],
            });
        })
    }
    ngOnInit() {
        this.modalTitle = '';
        this.validateForm = this.fb.group({
            rejectMemo: ['', [Validators.required]]
        });
        this.loadList();
    }
    loadList() {
        this.tableLoading = true;
        this.apiService.post('充值记录列表', { ...this.page }).then((res: any) => {
            this.dataList = res.data.list;
            this.page.pageNo = res.data.pageNo;
            this.pages = res.data.pages * 10;
            this.tableLoading = false;
        });
    };
    changeCurrentPage(e) {
        if (e) {
            this.page.pageNo = e;
            this.loadList();
        }
    }
    handleCancel() {
        this.isVisible = false;
	};
	detail(data){
		// this.selectedRowData = data;
		this.apiService.post('充值详情',{id:data.id}).then((res: any) => {
            if(res.data.userDepositMoneyDetail.images){
                res.data.userDepositMoneyDetail.images = res.data.userDepositMoneyDetail.images.split(",");
            }
			this.selectedRowData = res.data.userDepositMoneyDetail;
			this.isVisible = true;
		})
	}
	reject(item){
		this.modalService.confirm({
			nzTitle: '系统提示',
			nzContent: '审核驳回当前充值记录？',
			nzOnOk: () => {
				this.apiService.post('充值审核', { id: item.id,status: 'CANCELLED', bankSn:''}).then((res: any) => {
					this.loadList();
					this.nzMessageService.success('驳回成功！');
                });
			}
		})
	}
	sure(item){
		this.modalService.confirm({
			nzTitle: '系统提示',
			nzContent: '审核通过当前充值记录？',
			nzOnOk: () => {
				this.apiService.post('充值审核', { id: item.id,status: 'APPROVED', bankSn:''}).then((res: any) => {
					this.loadList();
					this.nzMessageService.success('审核成功！');
                });
			}
		})
	}
}
